<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>C7讲解-23航C | pansis.io</title>
<link rel="shortcut icon" href="https://github.pansis.site/favicon.ico">
<link href="https://github.pansis.site/styles/main.css" rel="stylesheet">
<link href="//at.alicdn.com/t/c/font_1678829_b85ccgkdqkr.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="pansis.io » Feed" href="https://github.pansis.site/atom.xml">
        <meta name="description" content="A sizeof
typedef定义结构体
typedef struct dhsajk {
    xxx
} inf,* pinf;

#include &lt;stdio.h&gt;
typedef struct dhsajk {
  ..." />
        <meta name="keywords" content="23航C" />
        <!-- OG -->
        <meta property="og:locale" content="zh_CN">
        <meta property="og:title" content="C7讲解-23航C" />
        <meta property="og:type" content="article" />
        <meta property="og:description" content="A sizeof
typedef定义结构体
typedef struct dhsajk {
    xxx
} inf,* pinf;

#include &amp;lt;stdio.h&amp;gt;
typedef struct dhsajk {
  ...">
        <meta property="og:url" content="https://github.pansis.site/post/C7讲解1-23航C/" />
        <meta property="og:site_name" content="pansis.io">
        <meta property="og:updated_time" content="2024-05-10">
        <meta property="og:image" content="" />
        <meta property="og:image:secure_url" content="">
        <meta property="og:image:alt" content="C7讲解-23航C">
        <!-- Twitter (post.ejs) -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="C7讲解-23航C">
        <meta name="twitter:description" content="A sizeof
typedef定义结构体
typedef struct dhsajk {
    xxx
} inf,* pinf;

#include &amp;lt;stdio.h&amp;gt;
typedef struct dhsajk {
  ...">
        <!-- <meta name="twitter:site" content="@WBoy0609">
        <meta name="twitter:creator" content="@WBoy0609"> -->
        <meta name="twitter:image" content="">
</head>

<body>
    <div class="main animated">
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <a href="https://github.pansis.site">pansis.io</a>
        </div>
    </div>
    <div class="my_socials">
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
        <a href="https://github.pansis.site/atom.xml" title="rss" target="_blank"><i class="iconfont icon-rss"></i></a>
    </div>
</div>

    <div class="header_menu">
        
            
                <a href="/" class="menu">首页</a>
            
        
            
                <a href="/tag/GWAaV2nvk/" class="menu">程序设计课程</a>
            
        
            
                <a href="/tag/24hangc" class="menu">比赛</a>
            
        
            
                <a href="/tag/L7r9STb75/" class="menu">Python教程</a>
            
        
            
                <a href="/tags" class="menu">分类</a>
            
        
        <div class="gridea-search-div">
            <form id="gridea-search-form" action="https://github.pansis.site/search/">
                <input class="gridea-search-input" autocomplete="off" spellcheck="false" name="q"/>
            </form>
        </div>
    </div>

            <div class="autopagerize_page_element">
                <div class="content">
                    <div class="post_page">
                        <div class="post animated fadeInDown">
                            <div class="post_title post_detail_title">
                                <h2>
                                    C7讲解-23航C
                                </h2>
                                <span class="article-info">
                                    2024-05-10, 883 words, 6 min read
                                </span>
                            </div>
                            <div class="post_content markdown">
                                <p class="md_block">
                                    <span class="md_line md_line_start md_line_end">
                                        <h1 id="a-sizeof"><code>A</code> sizeof</h1>
<p>typedef定义结构体</p>
<pre><code>typedef struct dhsajk {
    xxx
} inf,* pinf;
</code></pre>
<pre><code class="language-c">#include &lt;stdio.h&gt;
typedef struct dhsajk {
    char name[25];
    double R;
    short Imm;
    long L;
    struct node * next;
} inf,* pinf;
int main()
{
    inf A;
    printf(&quot;%d\n&quot;,sizeof(A.name));
    printf(&quot;%d\n&quot;,sizeof(A.R));
    printf(&quot;%d\n&quot;,sizeof(A.Imm));
    printf(&quot;%d\n&quot;,sizeof(A.L));
    printf(&quot;%d\n&quot;,sizeof(A.next));
    printf(&quot;%d\n&quot;,sizeof(A));
}
</code></pre>
<h1 id="b-叉积计算"><code>B</code> 叉积计算</h1>
<p>函数需要返回多个返回值</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
typedef struct vec
{
    int x, y, z;
} vec;
vec cross( vec u,  vec v)
{
    vec s ;
    s.x=u.y * v.z - u.z * v.y;
    s.y=u.z * v.x - u.x * v.z;
    s.z= u.x * v.y - u.y * v.x;

    return s;
}
void print_vec( vec a)
{
    printf(&quot;%d %d %d\n&quot;, a.x, a.y, a.z);
}
int main()
{
    vec a[6];
    for (int i = 1; i &lt;= 5; i++)
    {
        scanf(&quot;%d%d%d&quot;, &amp;a[i].x, &amp;a[i].y, &amp;a[i].z);
    }
    print_vec(cross(a[1], a[3]));
    print_vec(cross(a[3], a[5]));
    print_vec(cross(a[4], a[1]));
    print_vec(cross(a[2], a[5]));
    print_vec(cross(a[3], a[1]));
    return 0;
}
</code></pre>
<h1 id="c-最大做功"><code>C</code> 最大做功</h1>
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
typedef struct djsakl{
    int fx,fy,fz,w;
}inf,*pinf;
inf f[1005];
int main()
{
    int rx,ry,rz;
    scanf(&quot;%d%d%d&quot;,&amp;rx,&amp;ry,&amp;rz);
    int n;
    scanf(&quot;%d&quot;,&amp;n);
    int maxw=1&lt;&lt;31;
    for (int i = 0; i &lt; n; ++i) {
        scanf(&quot;%d%d%d&quot;,&amp;f[i].fx,&amp;f[i].fy,&amp;f[i].fz);
        f[i].w=f[i].fx*rx+f[i].fy*ry+f[i].fz*rz;
        if (f[i].w&gt;maxw)
            maxw=f[i].w;
    }
    for (int i = 0; i &lt; n; ++i) {
        if (f[i].w==maxw)
        {
            printf(&quot;%d %d %d\n&quot;,f[i].fx,f[i].fy,f[i].fz);
        }
    }
}
</code></pre>
<h1 id="d-firefly小姐的区间排序"><code>D</code> Firefly小姐的区间排序</h1>
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
int cmp(const void *p1, const void *p2) {  //升序排列
    int *a = (int *) p1, *b = (int *) p2; //这里排列的数据类型是int，如果要排列其他类型，需要把该行的int改成相应的类型
    if (*a &lt; *b)return -1;
    else if (*a &gt; *b) return 1;
    else return 0;
}

int cmp1(const void *p1, const void *p2) {  //降序排列
    int *a = (int *) p1, *b = (int *) p2;//这里排列的数据类型是int，如果要排列其他类型，需要把该行的int改成相应的类型
    if (*a &gt; *b)return -1;
    else if (*a &lt; *b) return 1;
    else return 0;
}
int num[10005];
int main()
{
    int n,op,l,r;
    scanf(&quot;%d&quot;,&amp;n);
    for (int i = 1; i &lt;=n ; ++i) {
        scanf(&quot;%d&quot;,&amp;num[i]);
    }
    while ((scanf(&quot;%d%d%d&quot;,&amp;op,&amp;l,&amp;r))!=EOF)
    {
        if (op==1)
        {
            qsort(num+l,r-l+1,sizeof(int),cmp);
        }
        else
        {
            qsort(num+l,r-l+1,sizeof(int),cmp1);
        }
    }
    for (int i = 1; i &lt;= n; ++i) {
        printf(&quot;%d &quot;,num[i]);
    }
}
</code></pre>
<h1 id="e-qaq字符串"><code>E</code> qaq字符串</h1>
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main()
{
    char s[1006];
    while (gets(s)!=NULL)
    {
        int num=0;
        int len=strlen(s);
        for (int i = 0; i &lt; len-1; ++i) {
            if (s[i]!=s[i+1])
                num++;
        }
        if (num==2 &amp;&amp;s[0]==s[len-1])
            printf(&quot;Yes\n&quot;);
        else
            printf(&quot;No\n&quot;);
    }
}
</code></pre>
<h1 id="f-复数算式"><code>F</code> 复数算式</h1>
<pre><code class="language-c">/* 
 Author: 潘宇恒(49720)
 Result: AC	Submission_id: 6191051
 Created at: Wed May 08 2024 20:08:52 GMT+0800 (China Standard Time)
 Problem: 7889	Time: 4	Memory: 1684
*/

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
typedef struct djskal{
    long long a,b;
}inf,*pinf;
inf add(inf z1,inf z2)
{
    inf temp;
    temp.a=z1.a+z2.a;
    temp.b=z1.b+z2.b;
    return temp;
}
inf mult(inf z1,inf z2)
{
    inf temp;
    temp.a=z1.a*z2.a-z1.b*z2.b;
    temp.b=z1.a*z2.b+z2.a*z1.b;
    return temp;
}
int main()
{
    inf z[5];
    for (int i = 1; i &lt;= 4; ++i) {
        scanf(&quot;%lld%lld&quot;,&amp;z[i].a,&amp;z[i].b);
    }
    int n,m;
    scanf(&quot;%d%d&quot;,&amp;n,&amp;m);
    inf temp;
    temp=add(z[1],z[2]);
    inf temp1=temp;
    for (int i = 0; i &lt; n-1; ++i) {
        temp1=mult(temp1,temp);
    }
    temp=mult(z[3],z[4]);
    temp=add(temp1,temp);
    temp1=temp;
    for (int i = 0; i &lt; m-1; ++i) {
        temp1=mult(temp1,temp);
    }
    printf(&quot;%lld %lld&quot;,temp1.a,temp1.b);
}
</code></pre>
<br />
                                            
                                </p>
                            </div>
                            <div class="post_footer">
                                
                                    <div class="meta">
                                        <div class="info"><span class="field tags"><i class="iconfont icon-tag-sm"></i>
                                                
                                                    <a href="https://github.pansis.site/tag/24hc/" class="article-info">
                                                        23航C
                                                    </a>
                                                    
                                            </span>
                                        </div>
                                    </div>
                                    
                                        
                            </div>
                        </div>
                        
                            
                                <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container" style="padding-bottom: 20px;"></div>
<script>
    var pageId = (location.pathname).substring(1, 49) // Ensure uniqueness and length less than 50
    pageId = pageId.endsWith('/') ? pageId.slice(0, -1) : pageId // 以斜杠结尾则去除
    var gitalk = new Gitalk({
        clientID: '9d5eba33618472c44a07',
        clientSecret: '065a85ed04333ceebfc4f01d7ca1674175730339',
        repo: 'fzxl2003.github.io',
        owner: 'fzxl2003',
        admin: ['fzxl2003'],
        id: pageId,
        distractionFreeMode: false  // Facebook-like distraction free mode
    })
    gitalk.render('gitalk-container')
</script>
                                    
                                        
                                                    
                    </div>
                </div>
            </div>
    </div>
    <div class="footer">
    
    <div class="powered_by">
        <a href="https://codeberg.org/kytrun/gridea-theme-one" target="_blank">Theme One,</a>
        <a href="https://open.gridea.dev/" target="_blank">Powered by Gridea&#65281;</a>
    </div>
    
    
        <div class="footer_slogan">
            Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
        </div>
    
    <div id="back_to_top" class="back_to_top">
        <span>△</span>
    </div>
    
</div>

<script src="https://github.pansis.site/media/scripts/util.js"></script>
        <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
        <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
        <script>hljs.highlightAll();</script>
</body>

</html>